/**********************************************************************
* <pre>
* FILE : ServiceActivityManageDao.java
* CLASS : ServiceActivityManageDao
*
* AUTHOR : PGM
*
* FUNCTION : 服务活动管理.
*
*
*======================================================================
* CHANGE HISTORY LOG
*----------------------------------------------------------------------
* MOD. NO.| DATE     | NAME | REASON | CHANGE REQ.
*----------------------------------------------------------------------
*         |2010-05-17| PGM  | Created |
* DESCRIPTION:
* </pre>
***********************************************************************/
/**
 * $Id: ServiceActivityManageDao.java,v 1.12 2011/02/15 09:40:53 zuoxj Exp $
 */
package com.infodms.dms.dao.claim.serviceActivity;
import java.sql.ResultSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.infodms.dms.bean.TtAsActivityBean;
import com.infodms.dms.common.Constant;
import com.infodms.dms.common.Utility;
import com.infodms.dms.dao.common.BaseDao;
import com.infodms.dms.po.TtAsActivityCharactorPO;
import com.infodms.dms.po.TtAsActivityMilagePO;
import com.infodms.dms.po.TtAsActivityPO;
import com.infodms.dms.util.StringUtil;
import com.infoservice.po3.bean.PO;
import com.infoservice.po3.bean.PageResult;
/**
 * Function       :  服务活动管理
 * @author        :  PGM
 * CreateDate     :  2010-06-01
 * @version       :  0.1
 */
@SuppressWarnings("unchecked")
public class ServiceActivityManageDao extends BaseDao{
	public static Logger logger = Logger.getLogger(ServiceActivityManageDao.class);
	private static final ServiceActivityManageDao dao = new ServiceActivityManageDao ();
	public  static final ServiceActivityManageDao getInstance() {
		return dao;
	}

	/**
	 * Function         : 服务活动管理
	 * @param           : 活动编号
	 * @param           : 活动开始日期
	 * @param           : 活动结束日期
	 * @param           : 当前页码
	 * @param           : 每页显示记录数
	 * @return          : 满足条件的服务活动管理信息，包含分页信息
	 * @throws          : Exception
	 * LastUpdate       : 服务活动管理
	 */
	public  PageResult<Map<String, Object>>  getAllServiceActivityManageInfo(TtAsActivityBean ActivityBean, int curPage,int pageSize) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("	SELECT A.ACTIVITY_ID,A.ACTIVITY_NAME, A.ACTIVITY_CODE, A.ACTIVITY_TYPE, to_char(A.STARTDATE,'yyyy-MM-dd')as STARTDATE,to_char(A.ENDDATE,'yyyy-MM-dd')as ENDDATE,TO_CHAR(COUNT(B.DEALER_ID)) AS NUM  FROM TT_AS_ACTIVITY A  \n");
		sql.append("    LEFT OUTER JOIN TT_AS_ACTIVITY_DEALER B ON A.ACTIVITY_ID = B.ACTIVITY_ID   \n");
		sql.append("    WHERE A.STATUS in( "+Constant.SERVICEACTIVITY_STATUS_01+") AND A.IS_DEL="+Constant.IS_DEL_00+" \n");//服务活动管理--服务活动活动状态:[10681001:尚未发布;10681002:已经发布;10681003:重新发布]
		if(!"".equals(ActivityBean.getCompanyId())&&!(null==ActivityBean.getCompanyId())){//公司ID不为空
			sql.append("		AND A.COMPANY_ID = '"+ActivityBean.getCompanyId()+"'  \n");
		}
		if(!"".equals(ActivityBean.getActivityId())&&!(null==ActivityBean.getActivityId())){//活动ID不为空
			sql.append("		AND A.ACTIVITY_ID = '"+ActivityBean.getActivityId()+"'  \n");
		}
		if(!"".equals(ActivityBean.getActivityCode())&&!(null==ActivityBean.getActivityCode())){//活动编号不为空
			sql.append("		AND UPPER(A.ACTIVITY_CODE) like UPPER('%"+ActivityBean.getActivityCode()+"%')\n");
		}
		if(!"".equals(ActivityBean.getActivityName())&&!(null==ActivityBean.getActivityName())){//活动编号不为空
			sql.append("		AND UPPER(A.ACTIVITY_NAME) like UPPER('%"+ActivityBean.getActivityName()+"%')\n");
		}
		if(!"".equals(ActivityBean.getStartdate())&&!(null==ActivityBean.getStartdate())){      //活动开始日期不为空
			sql.append("		AND A.STARTDATE >=to_date('"+ActivityBean.getStartdate()+" 00:00:00', 'yyyy-MM-dd HH24:mi:ss') \n");
		}
		if(!"".equals(ActivityBean.getEnddate())&&!(null==ActivityBean.getEnddate())){         //活动结束日期不为空
			sql.append("	    AND A.ENDDATE  <= to_date('"+ActivityBean.getEnddate()+" 23:59:59', 'yyyy-MM-dd HH24:mi:ss') \n");
		}
		sql.append("            GROUP BY A.ACTIVITY_ID, A.ACTIVITY_NAME,A.ACTIVITY_CODE,A.ACTIVITY_TYPE, A.STARTDATE,A.ENDDATE   \n");
		sql.append("            ORDER BY trim(A.ACTIVITY_CODE) desc  \n");
		PageResult<Map<String, Object>> ps = (PageResult<Map<String, Object>>) pageQuery(sql.toString(), null,  getFunName(), pageSize, curPage);
		return ps;
	}
	
	public PageResult<Map<String,Object>> getServiceActivityInfo(String con,int pageSize,int curPage){
		StringBuffer sql = new StringBuffer("\n");
		sql.append("select activity_id,activity_code,activity_name,status,\n");
		sql.append("to_char(startdate,'yyyy-MM-dd') as startdate,\n");
		sql.append("to_char(enddate,'yyyy-MM-dd') as enddate\n");
		sql.append("from tt_as_activity where 1=1\n");
		sql.append(con).append("order by activity_code\n");
		return (PageResult<Map<String, Object>>) pageQuery(sql.toString(), null,  getFunName(), pageSize, curPage);
	}

	@Override
	protected PO wrapperPO(ResultSet rs, int idx) {
		// TODO Auto-generated method stub
		return null;
	}
	/**
	 * Function       :  由车厂端[服务营销部]增加服务活动管理信息
	 * @param         :  request-活动编号、活动名称、活动类型、活动类别、活动开始日期、活动结束日期、处理方式、距活动结束日期几天上传活动总结
	 * @param         :          配件费用、工时费用、索赔、索赔是否为固定费用、解决方案说明、索赔申请填写指导
	 * @return        :  服务活动管理信息
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public static void serviceActivityManageAdd(TtAsActivityPO ActivityPO) {
		dao.insert(ActivityPO);
    }
	/**
	 * Function       :  新增之后---查询服务管理活动信息
	 * @param         :  request-活动ID
	 * @return        :  服务管理活动信息
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public  TtAsActivityBean  serviceActivityManageCommon(String activityId){
		List<Object> params = new LinkedList();
		StringBuilder sql = new StringBuilder("\n");
		sql.append("  SELECT STATUS,  COMPANY_ID,  CREATE_DATE, UPDATE_BY,  CREATE_By, UPDATE_DATE,  CLAIM_TYPE,VEHICLE_AREA,single_car_num,max_car,set_direct, \n");
		sql.append("  ACTIVITY_CODE, ACTIVITY_TYPE, to_char(STARTDATE,'yyyy-MM-dd')as STARTDATE,to_char(ENDDATE,'yyyy-MM-dd')as ENDDATE , ACTIVITY_ID, ACTIVITY_KIND,   \n");
		sql.append("  ACTIVITY_NAME, WORKTIME_FEE,  PART_FEE,  DEALWITH,  UPLOAD_PRE_PERIOD,   \n");
		sql.append("  SOLUTION, CLAIM_GUIDE,  IS_CLAIM,  IS_FIXFEE, CAR_NUM,  RELEASEDATE, OTHER_FEE ,ACTIVITY_FEE,MILAGE_CONFINE  \n");
		sql.append("  FROM TT_AS_ACTIVITY \n");
		sql.append("  WHERE  1=1 ");
		if (activityId!=null&&!("").equals(activityId)){
		sql.append(" AND ACTIVITY_ID = ? ");
		params.add(activityId);
		}
		TtAsActivityBean ActivityBean=new TtAsActivityBean();
		List list = dao.select(TtAsActivityBean.class, sql.toString(), params);
		if (list!=null){
			if (list.size()>0) {
				ActivityBean = (TtAsActivityBean) list.get(0);
			}
		}
		/*PageResult<TtAsActivityBean> rs = pageQuery(TtAsActivityBean.class,sql.toString(), null, 10, 1);
		List<TtAsActivityBean> ls = rs.getRecords();
		if (ls!=null){
			if (ls.size()>0) {
				ActivityBean = ls.get(0);
			}
		}
		*/
		return ActivityBean;
	}
	/**
	 * Function       :  修改服务管理活动信息
	 * @param         :  request-活动编号、活动名称、活动类型、活动类别、活动开始日期、活动结束日期、处理方式、距活动结束日期几天上传活动总结
	 * @param         :          配件费用、工时费用、索赔、索赔是否为固定费用、解决方案说明、索赔申请填写指导
	 * @return        :  服务管理活动信息
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public static void  serviceActivityManageUpdate(TtAsActivityPO ActivityPOCon,TtAsActivityPO ActivityPO){
		dao.update(ActivityPOCon, ActivityPO);
	}
	/**
	 * Function       :  删除服务管理活动信息
	 * @param         :  request-工单号
	 * @return        :  服务管理活动信息
	 * @throws        :  ParseException
	 * LastUpdate     :  2010-06-01
	 */
	public static void  serviceActivityManageDelete(String activityId,TtAsActivityPO ActivityPoContent){
			TtAsActivityPO  ActivityPO =new TtAsActivityPO();//activityId条件
			ActivityPO.setActivityId(Long.parseLong(activityId));
			dao.update(ActivityPO, ActivityPoContent);
	}
	/**
	 * Function         : 服务管理活动信息
	 * @param           : 活动ID
	 * @return          : 根据活动ID查询出具体 服务管理活动信息
	 * @throws          : Exception
	 * LastUpdate       : 2010-06-01
	 */
	public  TtAsActivityBean  getServiceActivityByActivityIdInfo(String activityId){
		List<Object> params = new LinkedList();
		StringBuilder sql = new StringBuilder();
		sql.append("  SELECT STATUS,  COMPANY_ID,  CREATE_DATE, UPDATE_BY,  CREATE_By, UPDATE_DATE,  CLAIM_TYPE, single_car_num,max_car,set_direct,   \n");
		sql.append("  ACTIVITY_CODE, ACTIVITY_TYPE, to_char(STARTDATE,'yyyy-MM-dd')as STARTDATE,to_char(ENDDATE,'yyyy-MM-dd')as ENDDATE , ACTIVITY_ID, ACTIVITY_KIND,   \n");
		sql.append("  ACTIVITY_NAME, WORKTIME_FEE,  PART_FEE,  DEALWITH,  UPLOAD_PRE_PERIOD,   \n");
		sql.append("  SOLUTION, CLAIM_GUIDE,  IS_CLAIM,  IS_FIXFEE, CAR_NUM,  RELEASEDATE, OTHER_FEE ,ACTIVITY_FEE,MILAGE_CONFINE  \n");
		sql.append("  FROM TT_AS_ACTIVITY \n");
		sql.append("  WHERE  1=1 ");
		if (activityId!=null&&!("").equals(activityId)){
		sql.append(" AND ACTIVITY_ID = ?  \n");
		params.add(activityId);
		}
		TtAsActivityBean ActivityBean=new TtAsActivityBean();
		List list = dao.select(TtAsActivityBean.class, sql.toString(), params);
		if (list!=null){
			if (list.size()>0) {
				ActivityBean = (TtAsActivityBean) list.get(0);
			}
		}
		
		return ActivityBean;
	}
	/**
	 * Function       :  服务管理活动信息---工时查询WorkingHours
	 * @param         :  request-活动ID
	 * @return        :  服务管理活动信息
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public  List<TtAsActivityBean>  getWorkingHoursInfoList(String activityId){
		List<Object> params = new LinkedList();
		StringBuilder sql = new StringBuilder();
		sql.append("  SELECT UPDATE_DATE,  CREATE_DATE, CREATE_BY, UPDATE_BY, ITEM_CODE, ITEM_ID, ACTIVITY_ID, ITEM_NAME, LABOR_FEE,  NORMAL_LABOR,  STAT_TITLE   \n");
		sql.append("  FROM TT_AS_ACTIVITY_REPAIRITEM \n");
		if (activityId!=null&&!("").equals(activityId)){
		sql.append("  WHERE  ACTIVITY_ID = ? ");
		params.add(activityId);
		}
		sql.append("order by ACTIVITY_ID desc ");
		List list = dao.select(TtAsActivityBean.class, sql.toString(), params);
        return list;
	}
	/**
	 * Function       :  服务管理活动信息---活动配件
	 * @param         :  request-活动ID
	 * @return        :  服务管理活动信息
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public  List<TtAsActivityBean>  getPartsList(String activityId){
		List<Object> params = new LinkedList();
		StringBuilder sql = new StringBuilder();
		sql.append("  SELECT UPDATE_DATE,  CREATE_DATE, CREATE_BY, UPDATE_BY, PART_NO, PART_NAME, IS_MAIN_PART, PART_AMOUNT, ACTIVITY_ID, PART_PRICE, PART_QUANTITY, PART_UNIT, PARTS_ID   \n");
		sql.append("  FROM TT_AS_ACTIVITY_PARTS \n");
		if (activityId!=null&&!("").equals(activityId)){
		sql.append("  WHERE  ACTIVITY_ID = ? \n");
		params.add(activityId);
		}
		sql.append("order by ACTIVITY_ID desc ");
		List list = dao.select(TtAsActivityBean.class, sql.toString(), params);
        return list;
	}
	/**
	 * Function       :  服务管理活动信息---活动其它项目
	 * @param         :  request-活动ID
	 * @return        :  服务管理活动信息
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public  List<TtAsActivityBean>  getNetItemList(String activityId){
		List<Object> params = new LinkedList();
		StringBuilder sql = new StringBuilder();
		sql.append("  select ID,  UPDATE_DATE, REMARK,  CREATE_DATE, CREATE_BY, UPDATE_BY, ITEM_CODE AS ITEM_CODES, ITEM_DESC,  AMOUNT, ACTIVITY_ID   \n");
		sql.append("  FROM TT_AS_ACTIVITY_NETITEM \n");
		if (activityId!=null&&!("").equals(activityId)){
		sql.append("  WHERE  ACTIVITY_ID = ? \n ");
		params.add(activityId);
		}
		sql.append("  ORDER BY ACTIVITY_ID desc \n");
		List list = dao.select(TtAsActivityBean.class, sql.toString(), params);
        return list;
	}
	/**
	 * Function       :  服务管理活动信息---车型列表
	 * @param         :  request-活动ID
	 * @return        :  服务管理活动信息
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public  List<TtAsActivityBean>  getVhclMaterialGroupList(String activityId){
		StringBuilder sql = new StringBuilder("\n");
		sql.append("select distinct gp.wrgroup_name as group_code,mg2.group_name group_name,mg.group_name parent_group_name,mg.group_code   parent_group_code\n");
		sql.append("from tt_as_wr_model_group gp,\n");
		sql.append("tt_as_wr_model_item mi,\n");
		sql.append(" tm_vhcl_material_group mg, TM_VHCL_MATERIAL_GROUP mg2,\n");
		sql.append("TT_AS_ACTIVITY_MGROUP m\n");
		sql.append("where gp.wrgroup_type = ").append(Constant.WR_MODEL_GROUP_TYPE_01).append("\n");
		sql.append("and gp.wrgroup_id = mi.wrgroup_id\n");
		sql.append("and mi.model_id=mg.group_id\n");
		sql.append("and mg.parent_group_id = mg2.group_id\n");
		sql.append("and mi.model_id = m.material_group_id\n");
		if (activityId!=null&&!("").equals(activityId)){
			sql.append("   and m.activity_id=").append(activityId).append("\n");
		}
		sql.append(" order by parent_group_name desc \n");
		List list = dao.select(TtAsActivityBean.class, sql.toString(), null);
        return list;
	}
	/**
	 * Function       :  服务管理活动信息---车龄定义列表
	 * @param         :  request-活动ID
	 * @return        :  服务管理活动信息
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public  List<TtAsActivityBean>  getActivityAgeList(String activityId){
		List<Object> params = new LinkedList();
		StringBuilder sql = new StringBuilder();
		sql.append("  SELECT ID as ID_AGE, UPDATE_DATE, CREATE_DATE,  CREATE_BY,  UPDATE_BY, ACTIVITY_ID,  to_char(SALE_DATE_END,'yyyy-MM-dd')as SALE_DATE_END,  to_char(SALE_DATE_START,'yyyy-MM-dd')as SALE_DATE_START, CUSTOMER_TYPE ,date_type  \n");
		sql.append("  FROM TT_AS_ACTIVITY_AGE \n");
		if (activityId!=null&&!("").equals(activityId)){
		sql.append("  WHERE ACTIVITY_ID = ?  \n");
		params.add(activityId);
		}
		sql.append(" ORDER BY ACTIVITY_ID desc \n");
		List list = dao.select(TtAsActivityBean.class, sql.toString(), params);
        return list;
	}
	/**
	 * Function       :  服务管理活动信息---车辆性质
	 * @param         :  request-活动ID
	 * @return        :  服务管理活动信息
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public  List<TtAsActivityBean>  getActivityCharactorList(String activityId){
		List<Object> params = new LinkedList();
		StringBuilder sql = new StringBuilder();
		sql.append("	SELECT ID,  CREATE_DATE, UPDATE_BY,  CREATE_BY, UPDATE_DATE, ACTIVITY_ID, CAR_CHARACTOR  \n");
		sql.append("    FROM TT_AS_ACTIVITY_CHARACTOR \n");
		if(!"".equals(activityId)&&!(null==activityId)){//活动ID
			sql.append(" WHERE ACTIVITY_ID = ? \n");
			params.add(activityId);
		}
		sql.append("     ORDER BY ACTIVITY_ID DESC  \n");
		List list = dao.select(TtAsActivityBean.class, sql.toString(), params);
        return list;
	}
	/**
	 * Function       :  服务管理活动信息---车辆信息
	 * @param         :  request-活动ID
	 * @return        :  服务管理活动信息
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public  PageResult<Map<String, Object>>  getActivityVehicleList(String activityId,String vin, int curPage,int pageSize) throws Exception {
		StringBuilder sql = new StringBuilder();
		sql.append("  SELECT a.VIN, b.DEALER_CODE, b.DEALER_SHORTNAME, a.CUSTOMER_NAME,a.LINKMAN_MOBILE,a.CUSTOMER_ADDRESS, a.POSTAL_CODE, a.LINKMAN,   \n");
		sql.append("  a.LINKMAN_ZONE_NUM, a.LINKMAN_OFFICE_PHONE, a.LINKMAN_FAMILY_PHONE, a.EMAIL,a.PROVINCE,AREA,a.TOWN,a.LINCENSE_TAG ,a.SALE_STATUS,a.REPAIR_STATUS \n");
		sql.append("  FROM TT_AS_ACTIVITY_VEHICLE  a left join TM_DEALER  b  on a.dealer_id=b.dealer_id where 1=1\n");
		if (null!=activityId&&!"".equals(activityId)){
			sql.append("  and ACTIVITY_ID = ' ");
			sql.append(activityId);
			sql.append("' \n");
			}
		if(StringUtil.notNull(vin))
			sql.append(" and a.vin like '%").append(vin).append("%'\n");
		sql.append(" ORDER BY a.VIN desc \n");
		PageResult<Map<String, Object>> ps = (PageResult<Map<String, Object>>) pageQuery(sql.toString(), null,  getFunName(), pageSize, curPage);
		return ps;
	}
	/**
	 * Function       :  新增之后---查询服务管理活动信息---售前车
	 * @param         :  request-活动ID
	 * @return        :  服务管理活动信息
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public  TtAsActivityBean  serviceActivityVehicleBeforeVehicleArea(){
		List<Object> params = new LinkedList();
		StringBuilder sql = new StringBuilder();
		sql.append("  SELECT CODES.CODE_ID,CODES.CODE_DESC   \n");
		sql.append("  FROM TC_CODE CODES \n");
		sql.append("  WHERE CODES.CODE_ID = "+Constant.SERVICEACTIVITY_VEHICLE_AREA_01);//服务活动车辆范围代码:售前车
		sql.append(" ORDER BY CODES.CODE_ID desc \n");
		TtAsActivityBean ActivityBean=new TtAsActivityBean();
		List list = dao.select(TtAsActivityBean.class, sql.toString(), params);
		if (list!=null){
			if (list.size()>0) {
				ActivityBean = (TtAsActivityBean) list.get(0);
			}
		}
		return ActivityBean;
	}
	/**
	 * Function       :  新增之后---查询服务管理活动信息---售后车
	 * @param         :  request-活动ID
	 * @return        :  服务管理活动信息
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public  TtAsActivityBean  serviceActivityVehicleAfterVehicleArea(){
		List<Object> params = new LinkedList();
		StringBuilder sql = new StringBuilder();
		sql.append("  SELECT CODES.CODE_ID,CODES.CODE_DESC   \n");
		sql.append("  FROM TC_CODE CODES \n");
		sql.append("  WHERE CODES.CODE_ID = "+Constant.SERVICEACTIVITY_VEHICLE_AREA_02);//服务活动车辆范围代码:售后车
		sql.append(" ORDER BY CODES.CODE_ID desc \n");
		TtAsActivityBean ActivityBean=new TtAsActivityBean();
		List list = dao.select(TtAsActivityBean.class, sql.toString(), params);
		if (list!=null){
			if (list.size()>0) {
				ActivityBean = (TtAsActivityBean) list.get(0);
			}
		}
		return ActivityBean;
	}
	/**
	 * Function       :  新增之后---查询服务管理活动信息---查询业务表中的服务活动车辆范围
	 * @param         :  request-活动ID
	 * @return        :  服务管理活动信息
	 * @throws        :  Exception
	 * LastUpdate     :  2010-06-01
	 */
	public  TtAsActivityBean  serviceActivityVehicleArea(String activityId){
		List<Object> params = new LinkedList();
		StringBuilder sql = new StringBuilder();
		sql.append("  SELECT ACTIVITY_ID, VEHICLE_AREA   \n");
		sql.append("  FROM TT_AS_ACTIVITY \n");
		sql.append("  WHERE 1=1   \n");//服务活动车辆范围代码:售前车
		if(!"".equals(activityId)&&null!=activityId){
			sql.append("  AND  ACTIVITY_ID="+activityId);//服务活动车辆范围代码:售前车
		}
		sql.append(" ORDER BY ACTIVITY_ID desc \n");
		TtAsActivityBean ActivityBean=new TtAsActivityBean();
		List list = dao.select(TtAsActivityBean.class, sql.toString(), params);
		if (list!=null){
			if (list.size()>0) {
				ActivityBean = (TtAsActivityBean) list.get(0);
			}
		}
		return ActivityBean;
	}
	/**
	 * Function       :  删除---车辆性质列表
	 * @param         :  request-activity_ID
	 * @return        :  服务活动管理--车辆性质列表
	 * @throws        :  Exception
	 * LastUpdate     :  2010-07-28
	 */
	public static void serviceActivityManageCharactorDelete(TtAsActivityCharactorPO CharactorPO) {
		TtAsActivityCharactorPO CPo=new TtAsActivityCharactorPO();
		CPo.setActivityId(CharactorPO.getActivityId());
		dao.delete(CPo);
    }
	public   PageResult<Map<String, Object>> getMilage(int pageSize, int curPage,String id) throws Exception {
		PageResult<Map<String, Object>> result = null;
		StringBuilder sql = new StringBuilder();

		sql.append("select q.*,(select count(*) from tt_as_activity_milage\n");
		sql.append(" where free_times=q.free_times and activity_id="+id+") AS A\n" );
		sql.append(" from tt_as_wr_qamaintain q");
		
		//sql.append(" select wno.news	_id from tt_as_wr_news_org  wno where wno.dealer_id="+dealerId+"  and status="+Constant.STATUS_ENABLE+") \n");
		//"com.infodms.dms.dao.claim.basicData.ClaimBasicParamsDao.claimBasicParamsQuery"
		result = (PageResult<Map<String, Object>>) pageQuery(sql.toString(), null, getFunName(), pageSize, curPage);
		return result;
	}
	public   List<Map<String, Object>> getMilageId(long id) throws Exception {
		PageResult<Map<String, Object>> result = null;
		StringBuilder sb = new StringBuilder();
		sb.append(" select * from  tt_as_wr_qamaintain where id= "+id);
		List<Map<String, Object>> list = pageQuery(sb.toString(), null,getFunName());
		return list;
	}
	
	public   List<Map<String, Object>> getMilageActivity(long id) throws Exception {
		PageResult<Map<String, Object>> result = null;
		StringBuilder sb = new StringBuilder();
		sb.append(" SELECT * from Tt_As_Activity_Milage where activity_id= "+id);
		List<Map<String, Object>> list = pageQuery(sb.toString(), null,getFunName());
		return list;
	}

	public void insertMilage(TtAsActivityMilagePO po ){
	factory.insert(po);
	}
	public void deleteMilage(String id ){
		StringBuilder sb = new StringBuilder();
		sb.append("delete from tt_as_activity_milage where activity_id= "+id);
		factory.delete(sb.toString(),null);
		}
}